

#include<bits/stdc++.h>
using namespace std;
const int mod = 998244353;
#define ll long long 


//时间复杂度位O(n)
// 多项式求值函数，使用霍纳法则
ll slove(ll x, const vector<ll>& a) {
    ll ret=a[0];
    for(int i=1;i<a.size();i++)
        ret=(ret*x%mod+a[i]%mod)%mod;
    return ret;
}

int main()
{
    int n; cin >> n;
    vector<ll>a(n + 1);
    //系数是从低到高的
    for (int i = 0; i <= n; i++) cin >> a[i];
    reverse(a.begin(),a.end());
    int t; cin >> t;
    while (t--)
    {
        int x; cin >> x;
        ll ret = slove(x, a);
        cout << ret;
        if (t) cout << " ";
    }
}
